using System;
using System.Reflection;
using System.Collections.Generic;
using System.Text;



namespace Open.Data.Persistence.Hashes
{
    //Implements a label for a type
    public sealed class TypeLabelHash : LabelHash<Type>, ITypeLabel
    {
        public TypeLabelHash(Type type): base(type)
        {

        }

        public TypeLabelHash(Type type, LabelHash parent): base(type, parent)
        {

        }

        public static TypeLabelHash GetBase(TypeLabelHash label)
        {
            CacheItem cache = Provider.Instance.ReflectionCache.Lookup(label.Item);

            if (!cache.IsUnderlying)
            {
                TypeLabelHash baseLabel = new TypeLabelHash(cache.BaseType, label);
                return GetBase(baseLabel);
            }

            return label;
        }

        //Returns the underlying type for the label for the ITypeLabel interface
        public Type Type
        {
            get
            {
                return Item;
            }
        }

        public override string ToString()
        {
            return Item.FullName;
        }
    }
}